package com.sy.controller.purchase;

import com.sy.bean.purchase.ChuStock;
import com.sy.bean.purchase.QueryChuRuStock;
import com.sy.bean.purchase.RuStock;
import com.sy.common.bean.PageBean;
import com.sy.common.bean.ResultBean;
import com.sy.common.controller.BaseController;
import com.sy.common.utils.BeanOfMap;
import com.sy.service.purchase.ChuRuStockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "purchase=退货出库管理")
@RequestMapping("/api/chuStock")
public class ChuRuStockController extends BaseController {

    @Autowired
    ChuRuStockService chuStockService;

    @ApiOperation("查询退货出库列表")
    @PostMapping("/query")
    public ResultBean query(@RequestBody QueryChuRuStock queryChuStock){
        PageBean bean=chuStockService.query(BeanOfMap.bom(queryChuStock));
        return success("查询成功",bean);
    }

    @ApiOperation("查询采购入库列表")
    @PostMapping("/que")
    public ResultBean queryRu(@RequestBody QueryChuRuStock queryChuStock){
        List bean=  chuStockService.queryRuStock(BeanOfMap.bom(queryChuStock));
        return success("查询成功",bean);
    }


    @ApiOperation("添加退货出库")
    @PostMapping("/add")
    public ResultBean add(@RequestBody ChuStock ChuStock){
        int rs=chuStockService.save(ChuStock);
        return rs==1?success("添加成功"):fail("添加失败");
    }

    @ApiOperation("添加入货单")
    @PostMapping("/save")
    public ResultBean save(@RequestBody RuStock ruStock){
        int rs=chuStockService.insert(ruStock);
        return success("添加成功");
    }
}
